from osv import fields,osv
import mx.DateTime
import tools.sql
from tools.translate import _

class project_budget_status(osv.osv):
    _name='kdvn.report.project.budget.status'
    _description='KDVN Report Project Budget Status'
    _auto=False
    _columns={  
              'budget_cat':fields.char('Budget Category',size=20,select=1),
              'cat_type':fields.char('Type of Cat.',size=250,select=1),
              'budget_id':fields.many2one('account.budget.post','Budget',select=1),
              'project_id':fields.many2one('kdvn.project','Project',size=20),
              'amount_vnd':fields.float('Budget Amount (VND)'),
              'pl_usd':fields.float('Budget Amount (USD)'),
              'order_vnd':fields.float('Order (VND)'),
              'order_usd':fields.float('Order (USD)'),
              'no_order_vnd':fields.float('No Order (VND)'),
              'no_order_usd':fields.float('No Order (USD)'),
              'payment_vnd':fields.float('Payment VND'),
              'budget_detail_ids':fields.one2many('kdvn.budget.sheet.detail','kdvn_kbd_id','Budget Details'),
              #'payment_usd':fields.float('Payment USD'),
              'over':fields.boolean('Over'),
              }
    
    def _get_quotation_lists(self, cr, uid, ids, name, arg, context=None):
        res = {}
        for id in ids:
            cr.execute('SELECT id FROM sale_order ' \
                    'WHERE project_e_id =%s or project_m_id=%s' % (id,id))
            res[id] = [x[0] for x in cr.fetchall()]
        return res
    
project_budget_status()

class kdvn_budget_sheet_detail(osv.osv):
    _table='vwkdvn_budget_sheet_details'
    _auto = False
    _name = 'kdvn.budget.sheet.detail'
    _description = 'KDVN Budget Sheet Detail'
    _columns={
                 'kdvn_kbd_id':fields.integer('KDVN Budget Data ID'),
                 'order_id':fields.many2one('purchase.order','Order'),
                 'po_type':fields.char('PO Type',size=25),
                 'order_vnd':fields.float("Order VND"),
                 'payment_vnd':fields.float("Payment VND"),
                 'original_price':fields.float("Original Price")
                 }
kdvn_budget_sheet_detail()

class kdvn_project(osv.osv):
    _name = "kdvn.project"
    _inherit = "kdvn.project"
  
    _columns={
             'budget_status_ids':fields.one2many('kdvn.report.project.budget.status','project_id','Budget Status'),
             }
kdvn_project()

